import os
from time import sleep

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.service import Service
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


ep = 'E:\Edge\Driver\edgedriver_win32\msedgedriver.exe'

@pytest.fixture(scope="function")
def generatedriver():
    service = Service(executable_path=ep)
    driver=webdriver.Edge(service=service)
    driver.maximize_window()
    driver.implicitly_wait(6)
    driver.get(os.getenv('BASEURL'))
    yield driver
    driver.quit()


@pytest.fixture()
def login_success():
    service = Service(executable_path=ep)
    driver = webdriver.Edge(service=service)
    driver.maximize_window()
    driver.implicitly_wait(6)
    driver.get(os.getenv('BASEURL'))

    # u = WebDriverWait(driver, 10, 1).until(
    #     EC.presence_of_element_located((By.NAME, 'username'))
    # )
    # u.clear()
    # u.send_keys("hogwarts")
    # p = WebDriverWait(driver, 10, 1).until(
    #     EC.presence_of_element_located((By.NAME, 'password'))
    # )
    # p.clear()
    # p.send_keys('test12345')
    b = WebDriverWait(driver, 10, 1).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, '#app > div > form > button'))
    )
    b.click()
    sleep(5)

    # ele = WebDriverWait(driver, 10, 1).until(
    #     EC.presence_of_element_located((By.LINK_TEXT, '首页'))
    # )
    # assert "首页" in ele.text

    yield driver
    driver.quit()


